﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ESoft.Core.Utils.Extensions
{
    public static class StringBuilderExtensions
    {
        /// <summary>
        /// 扩展：AppendFormattedLine
        /// </summary>
        /// <param name="this"></param>
        /// <param name="format"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public static StringBuilder AppendFormattedLine(this StringBuilder @this, string format, params object[] args)
            => @this.AppendFormat(format, args).AppendLine();
        /// <summary>
        /// 扩展：AppendLineWhen
        /// </summary>
        /// <param name="this"></param>
        /// <param name="predicate"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static StringBuilder AppendLineWhen(this StringBuilder @this, Func<bool> predicate, string value)
            => predicate() ? @this.AppendLine(value) : @this;
        /// <summary>
        /// 扩展：AppendLineIfTrue
        /// </summary>
        /// <param name="this"></param>
        /// <param name="condition"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static StringBuilder AppendLineIfTrue(this StringBuilder @this,bool condition, string value)
            => condition ? @this.AppendLine(value) : @this;
        /// <summary>
        /// 扩展：AppendLineIfElse
        /// </summary>
        /// <param name="this"></param>
        /// <param name="condition"></param>
        /// <param name="trueValue"></param>
        /// <param name="falseValue"></param>
        /// <returns></returns>
        public static StringBuilder AppendLineIfElse(this StringBuilder @this, bool condition, string trueValue,string falseValue)
            => condition ? @this.AppendLine(trueValue) : @this.AppendLine(falseValue);
    }
}
